using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Db.BLL
{
    public class ConSoftfile
    {
        public ConSoftfile()
        {
            GetPath();
        }
        private string FILE_NAME;

        #region
        public void GetPath()
        {
            string fullName;
            string myAppPath;
            fullName = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString();
            myAppPath = System.IO.Path.GetDirectoryName(fullName);
            this.FILE_NAME=myAppPath+@"\config\SoftConfig.ini";
            this.FILE_NAME=this.FILE_NAME.Substring(6);
        }

        public bool Exists()
        {
            if(File.Exists(FILE_NAME))
                return true;
            else
                return false;
 


        }
        public void Update(Model.ConSoft Model)
        {
            StreamWriter sw = new StreamWriter(FILE_NAME);
            sw.WriteLine("IsConFire=" + Model.IsConFire);
            sw.WriteLine("IsConWsd=" + Model.IsConWsd);
            sw.WriteLine("ConWsdDb=" + Model.ConWsdDb);
            sw.WriteLine("KuFangId=" + Model.KuFangId);
            sw.Close();
        }

        public void Add(Model.ConSoft Model)
        { 
        }

        public Model.ConSoft GetData()
        {
            string line;
            int count=0;
            Model.ConSoft Model =new Model.ConSoft();
            StreamReader file = new StreamReader(FILE_NAME);
            while ((line = file.ReadLine()) != null)
             {
                int n = line.IndexOf('=')+1;
                if (count == 0)
                {
                    Model.IsConFire = Convert.ToInt32(line.Substring(n).Trim().ToUpper());
                }
                else if (count == 1)
                {
                    Model.IsConWsd = Convert.ToInt32(line.Substring(n).ToUpper());
                }
                else if (count == 2)
                {
                    Model.ConWsdDb = line.Substring(n).Trim();
                }
                else if (count == 3)
                {
                    Model.KuFangId = Convert.ToInt32(line.Substring(n).Trim());
                }
                count++;
            }
            file.Close();
            return Model;
        }

        #endregion
    }
}
